<template>
  <div class="mod-config">
    <div class="avue-crud">
      <el-table :data="dataList" border v-loading="dataListLoading">
        <el-table-column prop="createTime" label="检查时间"></el-table-column>
        <el-table-column prop="billId" label="验光单号">
          <template slot-scope="scope">
            <el-button type="text" @click="checkDetailByOrder(scope.row.billId)">{{scope.row.billId}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="personName" label="姓名"></el-table-column>
        <el-table-column prop="cardNum" label="就诊卡号"></el-table-column>
        <el-table-column prop="optUserName" label="验光医生"></el-table-column>
        </el-table>
    </div>
    <div class="avue-crud__pagination">
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        background
        layout="total, sizes, prev, pager, next"
      ></el-pagination>
    </div>
    <order-info v-if="infoVisible" ref="infoDialog"></order-info>
  </div>
</template>

<script>
import { getSaleInfoPage } from "@/api/eims/customer.js";
import { getInfoListByPersonId } from '@/api/eims/sale'
import OrderInfo from '@/views/eims/optician/glassesinfo/detail'
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      infoVisible: false,
      dataForm: {
        key: ""
      },
      dataList: [],
      searchShow: true,
      pageIndex: 1,
      pageSize: 100,
      totalPage: 0,
      dataListLoading: false
    };
  },
  components: {
    OrderInfo
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  methods: {
    // 初始化数据
    init(personId) {
      this.dataForm.personId = personId
      this.visible = true
      this.$nextTick(() => {
        getInfoListByPersonId(this.dataForm.personId).then(response => {
          if(response.data.code == '0'){
            this.dataList = response.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    saleTypeFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return '隐形订做'
          break
        case "2":
          return '框镜订做'
          break
        case "3":
          return '隐形成品'
          break
        case "4":
          return '框镜成品'
          break
        case "5":
          return '辅料'
          break
      }
    },
    checkFlagFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return '内方'
          break
        case "0":
          return '辅料'
          break
      }
    },
    refundFlagFormatter(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return '已退货'
          break
        case "0":
          return '未退货'
          break
      }
    },
    //  查看配镜单详情
    checkDetailByOrder(order){
      this.infoVisible = true;
      this.$nextTick(() => {
        this.$refs.infoDialog.init('',order,'配镜单详情');
      });
    },
  }
};
</script>
